package at.spengergasse.abifs.SDJPATest.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

@Entity
@NamedQuery(name="Athlet.findByID", query="select a from Athlet a where a.a_id = ?1")
@Table(name="athlet")
public class Athlet implements Serializable
{
	
	private static final long serialVersionUID = -6410148842698899052L;

	@Column(name = "a_id")
	@Id
	@GeneratedValue
	private Long a_id;
	
	@Column(name = "a_firstname")
	private String a_firstname;
	
	@Column(name = "a_lastname")
	private String a_lastname;
	
	@Column(name = "a_birthday")
	private Date a_birthday;
	
	@Column(name = "a_tg_id")
	private Long a_tg_id;
	
	@ManyToOne
	@JoinColumn(name = "a_tg_id", insertable=false,updatable=false)
	private TrainingGroup trainingGroup;
	
	@Embedded
	private Adress adress;
	
	public Long getID()
	{
		return a_id;
	}
	
	public void setID(Long id)
	{
		this.a_id = id;
	}
	
	public String getFirstname()
	{
		return a_firstname;
	}
	
	public void setFirstname(String firstname)
	{
		this.a_firstname = firstname;
	}
	
	public String getLastname()
	{
		return a_lastname;
	}
	
	public void setLastname(String lastname)
	{
		this.a_lastname = lastname;
	}
	
	public Date getDate()
	{
		return (Date) a_birthday.clone();
	}
	
	public void setDate (Date birthday)
	{
		this.a_birthday = birthday;
	}
	
	public Long getTGID()
	{
		return a_tg_id;
	}
	
	public void setTGID(Long a_tg_id)
	{
		this.a_tg_id = a_tg_id;
	}
	
	public TrainingGroup getTrainingGroup()
	{
		return trainingGroup;
	}
	
	public Adress getAdress()
	{
		return adress;
	}
	
	public void setAdress(Adress adress)
	{
		this.adress = adress;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((a_birthday == null) ? 0 : a_birthday.hashCode());
		result = prime * result
				+ ((a_firstname == null) ? 0 : a_firstname.hashCode());
		result = prime * result + ((a_id == null) ? 0 : a_id.hashCode());
		result = prime * result
				+ ((a_lastname == null) ? 0 : a_lastname.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Athlet other = (Athlet) obj;
		if (a_birthday == null) {
			if (other.a_birthday != null)
				return false;
		} else if (!a_birthday.equals(other.a_birthday))
			return false;
		if (a_firstname == null) {
			if (other.a_firstname != null)
				return false;
		} else if (!a_firstname.equals(other.a_firstname))
			return false;
		if (a_id == null) {
			if (other.a_id != null)
				return false;
		} else if (!a_id.equals(other.a_id))
			return false;
		if (a_lastname == null) {
			if (other.a_lastname != null)
				return false;
		} else if (!a_lastname.equals(other.a_lastname))
			return false;
		return true;
	}
	
}
	